{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Necessary conditions for Graph coloring\n",
    "### Install pyQUBO from Recruit Communications Co. Ltd.\n",
    "    pip install pyqubo\n",
    "### Install openJij from Jij Inc.  (startup from Tohoku University)\n",
    "    pip install -U cmake (in google collaboratory, update cmake)\n",
    "    pip install open jij"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Add networkx for dealing with graph theory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "        pip install networkx"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Solve Graph Coloring"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### import pyQUBO, openJij, numpy and matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyqubo  import Array,Constraint, Placeholder\n",
    "import openjij as jij\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Array, Constrains and Placeholders are convenient classes from pyQUBO"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### import networkx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import networkx as nx"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prepare some graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "nodes = [0, 1, 2, 3, 4, 5]\n",
    "edges = [\n",
    "    (0, 1), (1, 2), (2, 4), (1, 3),\n",
    "    (3, 4), (4, 5), (3, 5)\n",
    "    ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Set nodes and edges on Graph G"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "G = nx.Graph()\n",
    "G.add_nodes_from(nodes)\n",
    "G.add_edges_from(edges)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAADnCAYAAAC9roUQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XmY1WXdx/H3dzZmAAVBwDXGxz0Ll8DMVFxBHJcMeCyXEMvysbTUrCZNS63RFEstn2xRyCU1FwIHlzJBn7JcknA3tXEjWURQYYZZzvf54/4JzDAzzAznnPssn9d1cXkx55zf+c7lzIf73L/7/t7m7oiISHaUxC5ARKSYKHRFRLJIoSsikkUKXRGRLFLoiohkkUJXRCSLFLoiIlmk0BURySKFrohIFil0RUSySKErIpJFCl0RkSxS6IqIZJFCV0Qki8piFyAiEkN1bf1wYAowChgMLAcWANMb6mqWZOp9Tf10RaSYVNfWjwFqgQmAA1XrPNwIGHAvUNdQV/N4ut9foSsiRaO6tv40YBpQSffTqymgCTinoa7mF+msQaErIkVhncDt34uXrSLNwavQFZGCl0wpzKVD4L5983dYvfBFrKQUgNJNhrL1l6/r+PJVwNiGupon0lGLbqSJSDGoJUwprGfIuNPYZPfx3b22Mnn9xHQUoiVjIlLQklUKE+h73pUAR1TX1g9LRz0KXREpdFMIqxQ6tXzuDN646njevvFcml5b0NXTPLnORtP0gogUulG0Xxa2xmYHTaV86LZYaTkrn3+YxXdezJZTr6Z8sy07PrUquc5G00hXRArd4K4e6LfVzpT064+VlTPw44fQb+tdaXyly/tlXV6nNxS6IlLolvf4mWZ0NxORjmIUuiJS6BYQdpq1k2r6gMZXn8Rbm/FUGx88+xCr33iGqv/6RGfXaEyus9E0pysiBW1p/U/+MvTwr/Wz0vJ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XYuo+XVFQyeP8TKBs8ArMS+u+wN2WDRrD67fWWrZcAR1TX1g/LWvGyRjpDt9Mu+2VDtsZTbbQsW3suY/Pif1O+zk20nlxHRILS/pt+waxkgxsr2la+S8uyt6gY9pHOHnbClKBkWTpDdwFheUr7N6iopP/On2L5IzeTam6i6c3nWPXy3xmw20GdXaMxuY6IdK3Tqbx1eVsrS2ddwcCPH0L50G07e4qm8iJJZ+jOIGztXc+Qcafjrc28ec0JLJ11OUPHnd5uudg6LLmOiHSt2yk49xRL75kGpWUMOazbhQqayosgbet0G+pqFlfX1t8LHEOHMC+t2oThE8/f0CVSwJx0NcERKWBdTsG5O+/MuZq2lcsZPvn7WGm3v+KayosgnSPXRqqbAAABKElEQVRdgDpCL4W+aEpeLyLd63QqD2DZ/T+n5Z03GD7pAkrK+3V3DU3lRZLW0E26hZ1D2NLbGx/2XlhvUaGIrKfTqbzWFYv5YP59NC96lTevOYnXp03i9WmT+KDDRqSEpvIiyasuYyISVNfW30UnU3k9lAJmNtTVTExvVdIT6Z5eACAJ0LGE5h1NrP9RqDH5+kxCkxsFrkjvaCovT2Xj5IhhdN5uboZumon0XbrbqEp2FNwZaSLFRFN5+UehK5LnkuY1tcARdH001hzC0Vi6WR2ZQlekQGgqLz8odEVEsigjqxdERKRzCl0RkSxS6IqIZJFCV0QkixS6IiJZpNAVEckiha6ISBYpdEVEskihKyKSRQpdEZEsUuiKiGSRQldEJIsUuiIiWfT/2Txjj4eev7sAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "nx.draw_networkx(G)\n",
    "plt.axis(\"off\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prepare binary variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "N = 6\n",
    "K = 3\n",
    "vartype = \"BINARY\"\n",
    "q = Array.create(\"q\",shape=[N,K],vartype=vartype)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\"q\" is name of variables  \n",
    "shape specifies the shape of variables as vector, matrix, or...  \n",
    "vartype selects -1 or 1 by \"SPIN\" and 0 or 1by \"BINARY\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Array([[Binary(q[0][0]), Binary(q[0][1]), Binary(q[0][2])],\n",
      "       [Binary(q[1][0]), Binary(q[1][1]), Binary(q[1][2])],\n",
      "       [Binary(q[2][0]), Binary(q[2][1]), Binary(q[2][2])],\n",
      "       [Binary(q[3][0]), Binary(q[3][1]), Binary(q[3][2])],\n",
      "       [Binary(q[4][0]), Binary(q[4][1]), Binary(q[4][2])],\n",
      "       [Binary(q[5][0]), Binary(q[5][1]), Binary(q[5][2])]])\n"
     ]
    }
   ],
   "source": [
    "print(q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Define cost function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "E1 = Constraint(np.sum((np.sum(q,axis=1)-1)**2,axis=0),\"K\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "E2 = 0\n",
    "for e in edges:\n",
    "    for k in range(K):\n",
    "        E2 += q[e[0],k]*q[e[1],k]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "Lam = Placeholder('Lam')\n",
    "E_cost = Lam*E1+E2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Compile the cost function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = E_cost.compile()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Get qubo matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "feed_dict = {'Lam': 5.0}\n",
    "Q, offset = model.to_qubo(feed_dict=feed_dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prepare simulation of quantum annealing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "sampler = jij.SQASampler(beta=10.0, gamma=1.0, trotter=4, step_length=10, step_num=10, schedule=None, iteration=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is done by quantum Monte-Carlo simulation  \n",
    "gamma = strength of quantum fluctuation  \n",
    "iteration = number of reads  \n",
    "step_num = number of MCS  \n",
    "trotter = Trotter number  \n",
    "step_length = length of MCS in the same gamma   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Let's simulate quantum annealing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = sampler.sample_qubo(Q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Show results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iteration : 1, minimum energy : -30.0, var_type : BINARY\n",
      "indices: ['q[3][0]', 'q[0][0]', 'q[1][1]', 'q[1][0]', 'q[3][2]', 'q[4][0]', 'q[4][2]', 'q[5][0]', 'q[5][2]', 'q[1][2]', 'q[5][1]', 'q[4][1]', 'q[2][1]', 'q[2][0]', 'q[3][1]', 'q[2][2]', 'q[0][2]', 'q[0][1]'] \n",
      "minmum energy state sample : [0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0]\n"
     ]
    }
   ],
   "source": [
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### minimum sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'q[3][0]': 0,\n",
       " 'q[0][0]': 0,\n",
       " 'q[1][1]': 1,\n",
       " 'q[1][0]': 0,\n",
       " 'q[3][2]': 1,\n",
       " 'q[4][0]': 1,\n",
       " 'q[4][2]': 0,\n",
       " 'q[5][0]': 0,\n",
       " 'q[5][2]': 0,\n",
       " 'q[1][2]': 0,\n",
       " 'q[5][1]': 1,\n",
       " 'q[4][1]': 0,\n",
       " 'q[2][1]': 0,\n",
       " 'q[2][0]': 0,\n",
       " 'q[3][1]': 0,\n",
       " 'q[2][2]': 1,\n",
       " 'q[0][2]': 1,\n",
       " 'q[0][1]': 0}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.samples[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### decode solution through openJij and pyQUBO"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'q': {3: {0: 0, 2: 1, 1: 0},\n",
       "  0: {0: 0, 2: 1, 1: 0},\n",
       "  1: {1: 1, 0: 0, 2: 0},\n",
       "  4: {0: 1, 2: 0, 1: 0},\n",
       "  5: {0: 0, 2: 0, 1: 1},\n",
       "  2: {1: 0, 0: 0, 2: 1}}}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dsol, broken, energy = model.decode_solution(response.samples[0], feed_dict = feed_dict, vartype=vartype)\n",
    "dsol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def decode_spin2(sol,vartype,feed_dict = None):\n",
    "    dsol, broken, energy = model.decode_solution(sol, feed_dict = feed_dict, vartype=vartype)\n",
    "    spin = np.zeros(N)\n",
    "    for keys1 in dsol[\"q\"]:\n",
    "        for keys2 in dsol[\"q\"][keys1]:\n",
    "            if dsol[\"q\"][keys1][keys2]==1:\n",
    "                spin[keys1] = keys2\n",
    "    return spin,energy,broken "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We define an original function for decoding the solution from openJij with pyQUBO into a standard expression.  \n",
    "reposense.min[\"min_state\"] is written on the indices in openJij.\n",
    "Here we arrange the original order of the variables by our function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "spin,energy,broken = decode_spin2(response.samples[0],vartype=vartype,feed_dict = feed_dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### check constraints"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{}\n"
     ]
    }
   ],
   "source": [
    "print(broken)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### show resulting graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAADnCAYAAAC9roUQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAH2ZJREFUeJzt3Xl4XGX9/vH3Z7J1XyyUsAlNywBWLQgWEVRAsIgiaxG/LP5QUKQYhVSQRfYdgxIF/aqXuABfoeyIiFUWZRMUECmloU1ZZWihe9IlzXx+fzyn2CaTNGlm5pyZ3K/rmqs0c2ZytzR3Tp7znOcxd0dERIojFXcAEZGBRKUrIlJEKl0RkSJS6YqIFJFKV0SkiFS6IiJFpNIVES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mAb0ZXH1IcAd2Ux6t3znVemKSFlw98XufiEwHngZeGzc+6tuy2b9cnIU7qLFHRx+wn8YXjeXcbvP5+Y7lnU+ZAhwQ75zqnRFpKy4+1J3vxgYf9k5mw1fvcarch136tkLqK423vp3Hb+9rpZp313IrDldNjcen82kd8lnPl1IE5GylM2kK4C3gC5rObS2ZRmz0zyef2g70uOrATj+1Axbb1nJ5edssO5OB3BTqrb5y/nKpTNdESlXHybcTtxF87w1VFbYe4ULMGliDbPmrOl8aAVwWD5DqXRFpFyNIZypdrGi1RkxfMP6GzE8xYoV2VyHD81m0pavUCpdESlX3fbbsKHGsuUbFuzyFVmGDev2JSpdEZGNWEQ3HZceX83aDufllv8OJ/xr1mom7lid6/CVqdrmnKfAm0KlKyLl6nkg93jBkBSHHTSM869+l9a2LI89tZJ7Hmjl2CO73DeRBf6Uz1AqXREpS6na5jXA9cCqXM9fd/lYVq50aj/YwjHfyHDdFZszcceazoe18d9bh/NCU8ZEpGxlM+ltCDdKDNrEt5gH7JDPBXB0pisiZStV2/wGcC1hIZu+WgmclO8Vx1S6IlLuzgLupm/Fu65wH8p3GJWuiJS16Ez1WOAHhPHdth4OXw4sAQ5P1TbfVIg8GtMVkQEjm0mPIew8cTphice10VM1wCzgSuCu6CJcQah0RWTAyWbSKWBbwnY97cDCVG3zgmJ8bpWuiEgRaUxXRKSIVLoiIkWk0hURKSKVrohIEal0RUSKSKUrIlJEKl0RkSJS6YqIFJFKV0SkiFS6IiJF9P8BjGF7mJlho3oAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "node_colors = [spin[node] for node in G.nodes()]\n",
    "\n",
    "nx.draw_networkx(G,node_color=node_colors)\n",
    "plt.axis(\"off\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
